<link rel="stylesheet" href="/admin/assets/module/formSelects/formSelects-v4.css"/>
<style>
    .layui-form-label {
        width: 100px;
    }
    .layui-input-block {
        margin-left: 130px;
    }
    .layui-form-select{
        width: 30%;
        float: left;
        margin-right: 10px;
    }
    .icon-del{
        font-size: 34px;
        color: red;
        float: left;
        cursor: pointer;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">环节名称：</label>
                                    <div class="layui-input-inline">
                                        <input name="name" class="layui-input" type="text" placeholder="请输入环节名称"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                            <div class="query-rt">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="returnOrderReviewProcessBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                        </div>
                        <div class="lay-btn-rt">

                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="returnOrderReviewProcessTable" lay-filter="returnOrderReviewProcessTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="returnOrderReviewProcessTableBar">
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<script type="text/html" id="jobsBar">
    <a class="layui-btn layui-btn-xs" lay-event="view">点击查看</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="returnOrderReviewProcessForm">
    <form lay-filter="returnOrderReviewProcessForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">评审环节名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入评审环节名称" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item" id="applyCompany">
            <label class="layui-form-label"><span style="color: red">*</span>适用公司</label>
            <div class="layui-input-block">
                <input name="selId" type="hidden"/>
                <select name="companyInfoId" type="text" class="layui-input" lay-filter="getCompanyInfo"
                        lay-verify="required" required></select>
                <div id="departmentId0" style="float: left;width: 30%;margin-right: 10px;"></div>
                <input type="hidden" name="departmentId">
                <select name="roleId" type="text" class="layui-input" lay-verify="required" required></select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <div class="layui-btn" type="button" id="addCompany">添加企业</div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">适用客诉类型</label>
            <div class="layui-input-block">
                <select name="customerComplaintTypes" xm-select="selCustomerComplaintTypes" xm-select-skin="default" lay-verify="required"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">适用订单类型</label>
            <div class="layui-input-block">
                <input name="orderTypes" type="checkbox" title="询价订单" checked="checked" value="0" />
                <input name="orderTypes" type="checkbox" title="打样订单" value="1" />
                <input name="orderTypes" type="checkbox" title="试产订单" value="2" />
                <input name="orderTypes" type="checkbox" title="量产订单" value="3" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">适用物料类型</label>
            <div class="layui-input-block">
                <select name="productTypes" xm-select="selProductTypes" xm-select-skin="default" lay-verify="required"></select>
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea  name="remark" placeholder="请输入描述" class="layui-textarea" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input name="isDeleted" type="checkbox" lay-skin="switch" value="1" checked="true" lay-text="启用|停用"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input name="sortNumber" placeholder="请输入排序" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="returnOrderReviewProcessFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 责任岗位弹窗 -->
<script type="text/html" id="jobsView">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格 -->
            <div class="table-bor">
                <table class="layui-table" id="jobsViewTable" lay-filter="jobsViewTable"></table>
            </div>
        </div>
    </div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'formSelects'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var formSelects = layui.formSelects;
        var orderTypesArr = ['询价订单', '打样订单', '试产订单', '量产订单'];

        // 渲染表格
        var insTb = table.render({
            elem: '#returnOrderReviewProcessTable',
            url: config.base + 'enterprise/sell/admin/returnOrderReviewProcess/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'}
                ,{field: 'name', align: 'center', title: '环节名称'}
                ,{align: 'center', title: '责任岗位', toolbar: '#jobsBar'}
                ,{field: 'orderTypes', align: 'center', title: '适用订单类型', templet: function (d) {
                        var orderTypes = d.orderTypes;
                        if(orderTypes){
                            if(orderTypes.indexOf(",") != -1){
                                var types = orderTypes.split(",");
                                for (var j = 0; j < types.length; j++) {
                                    if(j == 0){
                                        orderTypes = orderTypesArr[types[j]];
                                    }else{
                                        orderTypes += ","+orderTypesArr[types[j]];
                                    }
                                }
                            }else{
                                orderTypes = orderTypesArr[orderTypes];
                            }
                        }
                        return orderTypes;
                    }}
                ,{field: 'remark', align: 'center', title: '说明'}
                ,{field: 'sortNumber', align: 'center', title: '排序'}
                ,{field: 'createTime', align: 'center', title: '创建时间'}
                ,{field: 'isDeleted', align: 'center', title: '状态',templet:function (d) {
                        if(d.isDeleted){
                            return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="'+d.id+'" checked="'+d.isDeleted+'" lay-filter="isDeleted"  lay-text="启用|停用"/>';
                        }else{
                            return '<input name="isDeleted" type="checkbox" lay-skin="switch" value="'+d.id+'" lay-filter="isDeleted"   lay-text="启用|停用"/>';
                        }
                    }}
                ,{align: 'center', toolbar: '#returnOrderReviewProcessTableBar', title: '操作', width: 200}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                if(menuButton.indexOf("搜索") == -1){
                    $('.layui-form.toolbar').remove();
                }
                if(menuButton.indexOf("修改") == -1){
                    $("[lay-event='edit']").remove();
                }
                if(menuButton.indexOf("删除") == -1){
                    $("[lay-event='del']").remove();
                }
            }
        });

        // 工具条点击事件
        table.on('tool(returnOrderReviewProcessTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            }else if (obj.event === 'view') { // 点击查看责任岗位
                showViewModel(data);
            }
        });

        //监听排序
        table.on('sort(returnOrderReviewProcessTable)', function(obj){
            table.reload('returnOrderReviewProcessTable', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        form.on('switch(isDeleted)',function(obj){
            if(obj.elem.checked){
                enable(obj.value)
            }else{
                disable(obj.value)
            }
        })

        function enable(id){
            admin.req('enterprise/sell/admin/returnOrderReviewProcess/enable', {id:id}, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    insTb.reload('returnOrderReviewProcessTable');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'GET');
        }

        function disable(id){
            admin.req('enterprise/sell/admin/returnOrderReviewProcess/disable', {id:id}, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    insTb.reload('returnOrderReviewProcessTable');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'GET');
        }

        // 添加按钮点击事件
        $('#returnOrderReviewProcessBtnAdd').click(function () {
            showEditModel();
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '1000px',
                offset: '65px',
                title: data ? '修改退货订单评审环节' : '添加退货订单评审环节',
                content: $('#returnOrderReviewProcessForm').html(),
                success: function () {
                    function formatToTree (ary, pid, departmentId, pidName = 'parentId') {
                        return ary
                            .filter((item) => item[pidName] === pid)
                            .map((item) => {
                                // 通过父节点ID递归查询所有子节点
                                item.children = formatToTree(ary, item.id);
                                item.value = item.id;
                                item.selected = departmentId === item.id ? true : false;
                                return item;
                            });
                    }
                    function showSelectTree(treeData, element, roleItem, departmentId) {
                        xmSelect.render({
                            el: element,
                            model: {label: {type: 'text'}},
                            radio: true,
                            clickClose: true,
                            filterable: true,
                            tree: {
                                show: true,
                                strict: false,
                                // expandedKeys: [-1],
                                expandedKeys: false,
                            },
                            tips: '请选择',
                            // height: 'auto',
                            data() {
                                return formatToTree(treeData, '-1', departmentId);
                            },
                            on: function (data) {
                                console.log(data)
                                let depId = data.arr.length > 0 ? data.change[0].value : -1;
                                $(element).siblings("input[name='departmentId']").val(depId);
                                // 获取已经选取的岗位id
                                var ids = "";
                                $("select[name='roleId']").each(function (index, item) {
                                    if ($(item).val() != null) {
                                        if (ids == "") {
                                            ids = $(item).val();
                                        } else {
                                            ids += "," + $(item).val();
                                        }
                                    }
                                })
                                // 获取岗位
                                admin.req('user/admin/role/list', {
                                    limit: 9999,
                                    departmentId: depId,
                                    // filterIds: ids
                                }, function (res) {
                                    if (res.code == 200) {
                                        var html = '<option value="">请选择责任岗位</option>';
                                        for (var k = 0; k < res.data.length; k++) {
                                            html += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                                        }
                                        roleItem.html(html);
                                        form.render('select');
                                    } else {
                                        layer.msg('获取岗位失败', {icon: 2, time: 1000});
                                    }
                                }, 'GET');
                            },
                        });
                    }
                    function applyCompany(companyInfoItem, departmentItem, roleItem, length, del, companyInfoId, departmentId, roleId){
                        showSelectTree([], departmentItem, roleItem, departmentId)
                        // 获取公司
                        admin.req('user/admin/companyInfo/list', {limit:9999}, function (res) {
                            if (res.code==200) {
                                var html='<option value="">请选择公司</option>';
                                for(var k=0;k<res.data.length;k++){
                                    var elem = "";
                                    if(companyInfoId && companyInfoId == res.data[k].id){
                                        elem = "selected";
                                    }
                                    html+='<option value="'+res.data[k].id+'" '+elem+' >'+res.data[k].name+'</option>';
                                }
                                companyInfoItem.html(html);
                                form.render('select');
                                form.on('select(getCompanyInfo'+length+')', function (data) {
                                    if(data.value){
                                        // 获取部门
                                        admin.req('user/admin/department/list', {limit:9999, companyInfoId: data.value}, function (res) {
                                            if (res.code==200) {
                                                showSelectTree(res.data, departmentItem, roleItem, departmentId)
                                            } else {
                                                layer.msg('获取部门失败', {icon: 2, time: 1000});
                                            }
                                        }, 'GET');
                                    }else{
                                        roleItem.html("");
                                        departmentItem.html("");
                                        form.render('select');
                                    }
                                })
                            } else {
                                layer.msg('获取公司失败', {icon: 2, time: 1000});
                            }
                        }, 'GET');

                        if(companyInfoId){
                            // 获取部门
                            admin.req('user/admin/department/list', {limit:9999, companyInfoId: companyInfoId}, function (res) {
                                if (res.code==200) {
                                    showSelectTree(res.data, departmentItem, roleItem, departmentId)
                                } else {
                                    layer.msg('获取部门失败', {icon: 2, time: 1000});
                                }
                            }, 'GET');
                        }

                        if(departmentId){
                            // 获取岗位
                            admin.req('user/admin/role/list', {limit:9999, departmentId: departmentId}, function (res) {
                                if (res.code==200) {
                                    var html='<option value="">请选择责任岗位</option>';
                                    for(var k=0;k<res.data.length;k++){
                                        var elem = "";
                                        if(roleId && roleId == res.data[k].id){
                                            elem = "selected";
                                        }
                                        html+='<option value="'+res.data[k].id+'" '+elem+' >'+res.data[k].name+'</option>';
                                    }
                                    roleItem.html(html);
                                    form.render('select');
                                } else {
                                    layer.msg('获取岗位失败', {icon: 2, time: 1000});
                                }
                            }, 'GET');
                        }

                        if(del){
                            // 删除适用公司
                            del.click(function () {
                                $(this).parent().prev().prev().remove();
                                $(this).parent().prev().remove();
                                $(this).parent().remove();
                            })
                        }

                    }

                    if(data && data.id){
                        // 查询适用公司
                        admin.req('enterprise/sell/admin/returnOrderReviewProcessCompany/list', {limit: 9999, processId: data.id}, function (res) {
                            if (res.code == 200) {
                                var html = '';
                                for (var j = 0; j < res.data.length; j++) {
                                    if (j == 0) {
                                        html += '<label class="layui-form-label"><span style="color: red">*</span>适用公司</label>';
                                        html += '<div class="layui-input-block">\n' +
                                            '                                    <input name="selId" type="hidden" value="' + res.data[j].id + '" />\n' +
                                            '                                    <select name="companyInfoId" type="text" class="layui-input" lay-filter="getCompanyInfo" lay-verify="required" required ></select>\n' +
                                            "                <input name=\"departmentId\" type=\"hidden\" />\n" +
                                            "                <div style='float: left;width: 30%;margin-right: 10px;' id=\"departmentId" + 0 + "\"></div>\n" +
                                            '                                <select name="roleId" type="text" class="layui-input" lay-verify="required" required ></select>\n' +
                                            '                                </div>';
                                    } else {
                                        html += "<div style=\"height: 15px;\"></div>\n" +
                                            "            <label class=\"layui-form-label\"></label>\n" +
                                            "            <div class=\"layui-input-block\">\n" +
                                            "                <input name=\"selId\" type=\"hidden\" value='" + res.data[j].id + "' />\n" +
                                            "                <select name=\"companyInfoId\" type=\"text\" class=\"layui-input\" lay-filter=\"getCompanyInfo" + j + "\" lay-verify=\"required\" required ></select>\n" +
                                            "                <input name=\"departmentId\" type=\"hidden\" />\n" +
                                            "                <div style='float: left;width: 30%;margin-right: 10px;' id=\"departmentId" + j + "\"></div>\n" +
                                            "                <select name=\"roleId\" type=\"text\" class=\"layui-input\" lay-verify=\"required\" required ></select>\n" +
                                            "                <i class=\"layui-icon layui-icon-delete icon-del\" title=\"删除这一行\"></i>" +
                                            "            </div>";
                                    }
                                }
                                $("#applyCompany").html(html);
                                form.render();
                                $("#applyCompany").find(".layui-input-block").each(function (index, item) {
                                    var companyInfoId = res.data[index].companyInfoId;
                                    var departmentId = res.data[index].departmentId;
                                    var roleId = res.data[index].roleId;
                                    if (index == 0) {
                                        applyCompany($(item).find("select[name='companyInfoId']"), '#departmentId0', $(item).find("select[name='roleId']"), "", false, companyInfoId, departmentId, roleId);
                                    } else {
                                        applyCompany($(item).find("select[name='companyInfoId']"), `#departmentId${index}`, $(item).find("select[name='roleId']"), index, $(item).find("i.icon-del"), companyInfoId, departmentId, roleId);
                                    }
                                })
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    }else{
                        applyCompany($("select[name='companyInfoId']"), "#departmentId0", $("select[name='roleId']"), "");
                    }

                    // 添加企业
                    $("#addCompany").click(function () {
                        var length = $("#applyCompany").find(".layui-input-block").length;
                        var html = "<div style=\"height: 15px;\"></div>\n" +
                            "            <label class=\"layui-form-label\"></label>\n" +
                            "            <div class=\"layui-input-block\">\n" +
                            "                <select name=\"companyInfoId\" type=\"text\" class=\"layui-input\" lay-filter=\"getCompanyInfo" + length + "\" lay-verify=\"required\" required ></select>\n" +
                            "                <input name=\"departmentId\" type=\"hidden\" />\n" +
                            "                <div style='float: left;width: 30%;margin-right: 10px;' id=\"departmentId" + length + "\"></div>\n" +
                            "                <select name=\"roleId\" type=\"text\" class=\"layui-input\" lay-verify=\"required\" required ></select>\n" +
                            "                <i class=\"layui-icon layui-icon-delete icon-del\" title=\"删除这一行\"></i>" +
                            "            </div>";
                        $("#applyCompany").append(html);
                        form.render();
                        $("#applyCompany").find(".layui-input-block").each(function (index, item) {
                            if (index == length) {
                                applyCompany($(item).find("select[name='companyInfoId']"), `#departmentId${length}`, $(item).find("select[name='roleId']"), length, $(item).find("i.icon-del"));
                            }
                        })
                    })

                    // 获取所有客诉类型
                    admin.req('enterprise/sell/admin/customerComplaintType/list', {limit: 99999}, function (res) {
                        layer.closeAll('loading');
                        if (200 == res.code) {
                            // 渲染适用物料类型下拉框
                            var customerComplaintTypeSelData = new Array();
                            for (var i = 0; i < res.data.length; i++) {
                                customerComplaintTypeSelData.push({name: res.data[i].name, value: res.data[i].id});
                            }
                            formSelects.data('selCustomerComplaintTypes', 'local', {arr: customerComplaintTypeSelData});

                            // 回显user数据
                            if (data && data.customerComplaintTypes) {
                                console.log(data.customerComplaintTypes);
                                var rds = new Array();
                                var customerComplaintTypes = [];
                                if(data.customerComplaintTypes.indexOf(",") != -1){
                                    customerComplaintTypes = data.customerComplaintTypes.split(",");
                                }else{
                                    customerComplaintTypes.push(data.customerComplaintTypes);
                                }
                                for (var i = 0; i < customerComplaintTypes.length; i++) {
                                    rds.push(parseInt(customerComplaintTypes[i]));
                                }
                                formSelects.value('selCustomerComplaintTypes', rds);  // 回显多选框
                            }
                        } else {
                            layer.msg('获取客诉类型失败', {icon: 2});
                        }
                    }, 'GET');

                    // 获取所有物料类型
                    admin.req('enterprise/product/admin/productType/getTreeData', {limit: 99999}, function (res) {
                        layer.closeAll('loading');
                        if (200 == res.code) {
                            // 渲染适用物料类型下拉框
                            var productTypeSelData = new Array();
                            for (var i = 0; i < res.data.length; i++) {
                                productTypeSelData.push({name: res.data[i].name, value: res.data[i].id});
                            }
                            formSelects.data('selProductTypes', 'local', {arr: res.data});

                            // 回显user数据
                            if (data && data.productTypes) {
                                var rds = new Array();
                                var productTypes = [];
                                if (data.productTypes.indexOf(",") != -1) {
                                    productTypes = data.productTypes.split(",");
                                } else {
                                    productTypes.push(data.productTypes);
                                }
                                for (var i = 0; i < productTypes.length; i++) {
                                    rds.push(productTypes[i]);
                                }
                                formSelects.value('selProductTypes', rds);  // 回显多选框
                            }
                        } else {
                            layer.msg('获取物料类型失败', {icon: 2});
                        }
                    }, 'GET');

                    form.val('returnOrderReviewProcessForm', data);

                    if(data && data.orderTypes){
                        if(data.orderTypes.indexOf(",") != -1){
                            var types = data.orderTypes.split(",");
                            $("input[name='orderTypes']").each(function (index, item) {
                                if(types.indexOf($(item).val()) != -1){
                                    $(item).attr("checked", true);
                                }else{
                                    $(item).removeAttr("checked");
                                }
                            })
                        }else{
                            $("input[name='orderTypes']").each(function (index, item) {
                                if($(item).val() == data.orderTypes){
                                    $(item).attr("checked", true);
                                }else{
                                    $(item).ischecked = false;
                                    $(item).removeAttr("checked");
                                }
                            })
                        }
                    }

                    // 表单提交事件
                    form.on('submit(returnOrderReviewProcessFormSubmit)', function (d) {
                        layer.load(2);
                        d.field.customerComplaintTypes = formSelects.value('selCustomerComplaintTypes', 'valStr');
                        d.field.productTypes = formSelects.value('selProductTypes', 'valStr');
                        var isDeleted=$("form input[name='isDeleted']").prop("checked");
                        if(!isDeleted){
                            d.field.isDeleted=false;
                        }else{
                            d.field.isDeleted=true;
                        }
                        var returnOrderReviewProcessCompanyList = [];
                        $("#applyCompany").find(".layui-input-block").each(function (index, item) {
                            var returnOrderReviewProcessCompany = {};
                            returnOrderReviewProcessCompany.id = $(item).find("input[name='selId']").val();
                            returnOrderReviewProcessCompany.companyInfoId = $(item).find("select[name='companyInfoId']").val();
                            returnOrderReviewProcessCompany.departmentId = $(item).find("input[name='departmentId']").val();
                            returnOrderReviewProcessCompany.roleId = $(item).find("select[name='roleId']").val();
                            returnOrderReviewProcessCompanyList.push(returnOrderReviewProcessCompany);
                        })
                        d.field.returnOrderReviewProcessCompanyList = returnOrderReviewProcessCompanyList;
                        var orderTypess = "";
                        $("input[name='orderTypes']:checked").each(function (index, item) {
                            if(index == 0){
                                orderTypess = $(item).val();
                            }else{
                                orderTypess += ","+$(item).val();
                            }
                        })
                        d.field.orderTypes = orderTypess;
                        admin.req(data ? 'enterprise/sell/admin/returnOrderReviewProcess/update' : 'enterprise/sell/admin/returnOrderReviewProcess/add', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('returnOrderReviewProcessTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }

        // 显示详情弹窗
        function showViewModel(data) {
            admin.open({
                type: 1,
                area: '60%',
                offset: '65px',
                title: '查看责任岗位',
                content: $('#jobsView').html(),
                success: function () {

                    // 渲染表格
                    var insTb = table.render({
                        id: '#jobsViewTable',
                        elem: '#jobsViewTable',
                        url: config.base + 'enterprise/sell/admin/returnOrderReviewProcessCompany/getRoleData',
                        where: {processId: data.id},
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers'}
                            ,{field: 'companyInfoName', title: '公司'}
                            ,{field: 'departmentName', title: '部门'}
                            ,{field: 'name', title: '岗位'}
                        ]]
                    });

                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/sell/admin/returnOrderReviewProcess/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 导出excel
        $('#returnOrderReviewProcessBtnExport').click(function () {
            var checkRows = table.checkStatus('returnOrderReviewProcessTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>